function ajaxSubmit(formid){
  var form = $('#'+formid);
  var url = form.attr('action');
  var data = {};
  data = form.serializeArray();
  _submitFn(url,data);
}


function _submitFn(url,data){
  $.ajax({
    type: 'POST',
    url: url,
    data: data,
    cache: false,
    dataType:'json',
    success: okCallback,
    error: errorCallback
  });
}


function refresh(){
    setTimeout(function(){
        location.reload(true);
    },1000);
}


function okCallback(msg){
  if(msg.status == 0){
    parent.layer.msg(msg.info, {shade: 0.3}); return false;
  }else if(msg.status == 1){
    parent.layer.msg(
      msg.info,
      {shade: 0.3},
      function(){
        parent.location.reload();return true;
      }
    )
  }
}

function errorCallback(){
  layer.msg('操作失败!');return false;
}

function closeParent(){
  var index = parent.layer.getFrameIndex(window.name);
  parent.layer.close(index);
}


function showConfirm(url,msg){
  var msg = msg?msg:'确定要删除吗?';
  layer.confirm(msg,function(index){
    $.ajax({
      type: 'POST',
      url: url,
      cache: false,
      dataType:'json',
      success: function(msg){
        layer.msg(msg.info,{shade: 0.3});
        refresh();
      },
      error: errorCallback
    });

  });

}



function showWindow(title,url,width,height){
    var win_width = width?width + 'px':'500px';
    var win_height = height?height + 'px':'500px';
    layer.open({
        type: 2,
        title: title?title:'',
        fix: false,
        shadeClose: false,
        maxmin: true,
        area: [win_width, win_height],
        content: [url,'no'],
        scrollbar: false
    });
}
